<?php
require_once ($_SERVER ['DOCUMENT_ROOT'] . '/aduc272/configs/configs.php');
require_once (MODEL_PATH . "cv/cvContact.php");

$name = "";
$email = "";
$msg = "";

if(isset($_POST['name'])) {
	$name = $_POST['name'];
}
if(isset($_POST['email'])) {
	$email = $_POST['email'];
}
if(isset($_POST['msg'])) {
	$msg = $_POST['msg'];
}
 
 
if($msg != "")
{	
    try {    
    	// add message contact to database    	
    	$contact = new CvContact();	
    	$contact->setMessage($msg);
    	$contact->setEmail($email);
    	$contact->setName($name);
    	$contact->add();
    	    	
    	// send message to ducnguyen272@gmail.com
    	$to      = 'ducnguyen272@gmail.com';
	    $subject = 'Contact ' . ROOT_WEB . 'cv/';
	    $message = 'Message from ' + $name 
	    					+ '(' . $email . "):\r\n" 
	    					+ $msg;
	    /*
	    $headers = 'From: webmaster@example.com' . "\r\n" .
	    'Reply-To: webmaster@example.com' . "\r\n" .
	    'X-Mailer: PHP/' . phpversion();
	    */
    	mail($to, $subject, $message);
    } catch (Exception $ex){
    	echo $ex;
    	return;
    }
    
	echo "1"; // successful
}
else 
{
	echo 0; // failed
}


/*------------------------------FUNCTIONS---------------------------------*/

?>